package io.renren.modules.common.service.impl;

import io.renren.modules.common.viewdo.SelectOption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.common.dao.WelfareDao;
import io.renren.modules.common.entity.WelfareEntity;
import io.renren.modules.common.service.WelfareService;


@Service("welfareService")
public class WelfareServiceImpl extends ServiceImpl<WelfareDao, WelfareEntity> implements WelfareService {


    @Autowired
    private WelfareDao welfareDao;



    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<WelfareEntity> page = this.page(
                new Query<WelfareEntity>().getPage(params),
                new QueryWrapper<WelfareEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<SelectOption> selectOptionWelfare() {
        List<SelectOption> topList = new ArrayList<>();
        List<WelfareEntity> welfareEntities = welfareDao.selectList(null);
        topList = welfareEntities.stream().map(item -> new SelectOption(item.getId().toString(),item.getWelfareName())).collect(Collectors.toList());
        return topList;
    }
}